package cn.lliiooll;

import cn.lliiooll.cmd.HelpCmd;
import cn.lliiooll.cmd.MainCmd;
import cn.lliiooll.config.Config;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;

public class HelpMe extends JavaPlugin {

    public static String pre = "&c&l[&bHelpMe&c&l] &f".replaceAll("&", "§");
    public static HelpMe instance;


    @Override
    public void onLoad() {
        info("启动中...");
        instance = this;
    }

    @Override
    public void onEnable() {
        Bukkit.getPluginCommand("helpme").setExecutor(new MainCmd());
        Bukkit.getPluginCommand("helpme").setTabCompleter(new MainCmd());
        Bukkit.getPluginCommand("help").setExecutor(new HelpCmd());
        Bukkit.getPluginCommand("help").setTabCompleter(new MainCmd());
        Bukkit.getPluginCommand("?").setExecutor(new HelpCmd());
        Bukkit.getPluginCommand("?").setTabCompleter(new HelpCmd());
        info("读取配置....");
        Config.init();
        info(Config.papi ? (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI") ? "PlaceholderAPI已安装,启用占位符..." : "您在配置文件中启用了占位符支持,但是PlaceholderAPI未安装,所以将不会支持占位符") : "PlaceholderAPI支持未启用...");
        if (!Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) {
            Config.papi = false;
            Config.save();
        }
        info("插件启动完毕.");
    }


    @Override
    public void onDisable() {
        Config.save();
        Config.saveAllSub();
        info("插件已关闭");
    }

    public static void info(String msg) {
        Bukkit.getConsoleSender().sendMessage(pre + "§2" + msg.replaceAll("&", "§"));
    }
}
